package servlet.goods;

import domain.Goods;
import service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/goods_admin.do")
public class GoodsAllServletAdmin extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        String goodsName = request.getParameter("goods");
        if (goodsName == null) {
            goodsName = "";
        }
        GoodsService goodsService = new GoodsService();
        List<Goods> goods = goodsService.findAll(goodsName);
        request.setAttribute("goods", goods);
        request.getRequestDispatcher("first_admin.jsp").forward(request, response);

    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
